import { BaseService, type PageResult } from '../../shared/services/base-service'
import type { ApiResponse } from '../../../types/api' 

// 灵感实体类型
export interface Inspiration {
  id?: number
  title: string
  content: string
  tags?: string // 标签，多个标签逗号分隔
  rating?: number // 星级，1-5星
  isPublic?: number // 是否公开 (0-私有, 1-公开)
  userId: number
  bookId?: number // 书籍ID
  createTime?: string
  updateTime?: string
}

// 分页查询参数
export interface InspirationQueryParams {
  page: number
  size: number
  title?: string
  tags?: string
  rating?: number
  userId?: number
  bookId?: number
}

// 灵感管理API服务
class InspirationService extends BaseService {
  // 获取灵感列表（分页）
  async getInspirations(params: InspirationQueryParams): Promise<ApiResponse<PageResult<Inspiration>>> {
    return this.get('/novel/inspiration/list', params)
  }

  // 获取灵感详情
  async getInspirationById(id: number): Promise<ApiResponse<Inspiration>> {
    return this.get(`/novel/inspiration/${id}`)
  }

  // 创建灵感
  async createInspiration(inspiration: Inspiration): Promise<ApiResponse<Inspiration>> {
    return this.post('/novel/inspiration', inspiration)
  }

  // 更新灵感
  async updateInspiration(id: number, inspiration: Partial<Inspiration>): Promise<ApiResponse<Inspiration>> {
    return this.put(`/novel/inspiration/${id}`, inspiration)
  }

  // 删除灵感
  async deleteInspiration(id: number): Promise<ApiResponse<string>> {
    return this.delete(`/novel/inspiration/${id}`)
  }

  // 获取用户灵感列表
  async getUserInspirations(userId: number, page = 1, size = 10): Promise<ApiResponse<PageResult<Inspiration>>> {
    return this.get(`/novel/inspiration/user/${userId}`, { page, size })
  }

  // 获取书籍灵感列表
  async getInspirationsByBookId(bookId: number): Promise<ApiResponse<Inspiration[]>> {
    return this.get(`/novel/inspiration/book/${bookId}`)
  }

  // 按标签查询灵感
  async getInspirationsByTags(tags: string, page = 1, size = 10): Promise<ApiResponse<PageResult<Inspiration>>> {
    return this.get('/novel/inspiration/tags', { tags, page, size })
  }
}

export const inspirationService = new InspirationService()